$(document).ready(function() {
	showUser();
});
function showUser() {
	$("#userRole")
			.datagrid(
					{
						url : "ksmanage_showKsList.do",
						rownumbers : true,
						pagination : true,
						rownumber : true,
						fitColumns : true,
						striped : true,
						collapsible : true,
						remoteSort : false,
						nowrap : false,
						checkOnSelect : false,
						singleSelect : true,
						loadMsg : '数据加载中，请稍等...',
						columns : [ [
								{
									field : 'dname',
									title : '科室名称',
									width : 100,
									align : 'center'
								},
								{
									field : 'descript',
									title : '描述',
									width : 100,
									align : 'center',
								},
								{
									field : 'update',
									title : '操作',
									width : 100,
									align : 'center',
									formatter : function(value, rowData,
											rowIndex) {
										return "<a href='javascript:void(0);' onclick='userDelete("
												+ parseInt(rowData.id)
												+ ")'>删除</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='showUpdate("
												+ parseInt(rowData.id)
												+ ")'>修改</a>";
									}
								} ] ]
					});
}
function showUpdate(ksid) {
	$("#add_ks").dialog({
		closed : false
	});
	$.post("ksmanage_showOne.do", {
		"ksId" : ksid
	}, function(data) {
		$("#dname").attr("readonly","readonly");
		$("#dname").val(data.dname);
		$("#ks_descript").val(data.descript);
	}, "json");
}
function ks_save() {
	var dname = $("#dname").val();
	var ks_descript = $("#ks_descript").val();
	if (dname == "") {
		alert("科室名称不能为空");
		return;
	}
	if (ks_descript == "") {
		alert("科室描述不能为空");
		return;
	}
	$.post("ksmanage_save.do", {
		"dname" : dname,
		"descript" : ks_descript
	}, function(data) {
		if (data.success == "success") {
			$.messager.alert("提示", "操作成功");
			showUser();
			$("#add_ks").dialog({
				closed : true
			});
		} else {
			$.messager.alert("提示", "操作失败");
		}
	}, "json");
}
function userDelete(id) {
	$.post("ksmanage_delete.do", {
		"id" : id
	}, function(data) {
		if (data.success == "success") {
			$.messager.alert("提示", "操作成功");
			showUser();
		} else {
			$.messager.alert("提示", "操作失败");
		}
	}, "json");
}

function showDialog() {
	$("#add_ks").dialog({
		closed : false
	});
}